import 'package:aihu_getx_app/app/interceptors/login_intercept_chain.dart';
import 'package:aihu_getx_app/app/routes/app_pages.dart';
import 'package:aihu_getx_app/utils/constants.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class RouteAuthMiddleware extends GetMiddleware {
  final String clientType;

  RouteAuthMiddleware(this.clientType, {super.priority});

  @override
  RouteSettings? redirect(String? route) {
    if (TextUtil.isEmpty(route)) {
      return super.redirect(route);
    }
    if (LoginInterceptChain.isLogin()) {
      return super.redirect(route);
    }
    // Future.delayed(
    //   const Duration(seconds: 1),
    //   () => CustomGetUtil.snackbar(
    //     "提示",
    //     "请先登录",
    //   ),
    // );
    return RouteSettings(
      name: clientType == ClientType.d.type
          ? Routes.adminLogin
          : Routes.userLogin,
      arguments: {
        Constants.jumpArgument: route,
      },
    );
  }
}
